﻿/**
* project     : 营养学会
* version     : 1.0
* last change : 2013/02/21
*/
$(function(){
	/*二级导航*/
	var timeout = 500;
	var closetimer = 0;
	var ddmenuitem = 0;

	function nav_open(){
		nav_canceltimer();
		nav_close();
		ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
	}
	function nav_close(){
		if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	}
	function nav_timer(){
		closetimer = window.setTimeout(nav_close, timeout);
	}
	function nav_canceltimer(){
		if(closetimer){	
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}
	$(document).ready(function(){
		$('.nav-list > li').bind('mouseover', nav_open);
		$('.nav-list > li').bind('mouseout',  nav_timer);
	});
	document.onclick = nav_close;
	
	
	/*placeholder封装*/
	;(function($){
		$.fn.extend({
			placeholder: function() {
				if ('placeholder' in document.createElement('input')) {
					return this
				} else {
					return this.each(function() {
						var _this = $(this),
						this_placeholder = _this.attr('placeholder');
						_this.val(this_placeholder).focus(function() {
							if (_this.val() === this_placeholder) {
								_this.val('');
							}
						}).blur(function() {
							if (_this.val().length === 0) {
								_this.val(this_placeholder);
							}
						});
					});
				}
			}
		})
	})(jQuery);
	$("input:text").placeholder();
})